package com.rla.controller;

import java.util.List;
import java.util.Arrays;

import com.rla.common.annotation.Anonymous;
import com.rla.domain.BaseDrugOnline;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.rla.common.annotation.RepeatSubmit;
import com.rla.common.annotation.Log;
import com.rla.common.core.controller.BaseController;
import com.rla.common.core.domain.PageQuery;
import com.rla.common.core.domain.R;
import com.rla.common.utils.validate.AddGroup;
import com.rla.common.utils.validate.EditGroup;
import com.rla.common.enums.BusinessType;
import com.rla.common.utils.poi.ExcelUtil;
import com.rla.domain.vo.BaseDrugOnlineVo;
import com.rla.domain.bo.BaseDrugOnlineBo;
import com.rla.service.IBaseDrugOnlineService;
import com.rla.common.core.page.TableDataInfo;

/**
 * 线上商品（套餐、积分商品）共用
 *
 * @author rla
 * @date 2025-08-04
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/drug")
public class BaseDrugOnlineController extends BaseController {

    private final IBaseDrugOnlineService iBaseDrugOnlineService;

    /**
     * 查询线上商品（套餐、积分商品）共用列表
     */
    @GetMapping("/list")
    public TableDataInfo<BaseDrugOnlineVo> list(BaseDrugOnlineBo bo, PageQuery pageQuery) {
        return iBaseDrugOnlineService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出线上商品（套餐、积分商品）共用列表
     */
    @Log(title = "线上商品（套餐、积分商品）共用", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(BaseDrugOnlineBo bo, HttpServletResponse response) {
        List<BaseDrugOnlineVo> list = iBaseDrugOnlineService.queryList(bo);
        ExcelUtil.exportExcel(list, "线上商品（套餐、积分商品）共用", BaseDrugOnlineVo.class, response);
    }

    /**
     * 获取线上商品（套餐、积分商品）共用详细信息
     *
     * @param id 主键
     */
    @Anonymous
    @GetMapping("/{id}")
    public R<BaseDrugOnlineVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iBaseDrugOnlineService.queryById(id));
    }

    /**
     * 新增线上商品（套餐、积分商品）共用
     */
    @Log(title = "线上商品（套餐、积分商品）共用", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody BaseDrugOnlineBo bo) {
        return toAjax(iBaseDrugOnlineService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改线上商品（套餐、积分商品）共用
     */
    @Log(title = "线上商品（套餐、积分商品）共用", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody BaseDrugOnlineBo bo) {
        return toAjax(iBaseDrugOnlineService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除线上商品（套餐、积分商品）共用
     *
     * @param ids 主键串
     */
    @Log(title = "线上商品（套餐、积分商品）共用", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iBaseDrugOnlineService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }


    /**
     * 查询线上商品（套餐、积分商品）共用列表
     */
    @Anonymous
    @GetMapping("/queryGoodsList")
    public TableDataInfo<BaseDrugOnlineVo> queryGoodsList(BaseDrugOnlineBo bo, PageQuery pageQuery) {
        return iBaseDrugOnlineService.queryGoodsList(bo, pageQuery);
    }

    /**
     * 获取线上商品（套餐、积分商品）共用详细信息
     *
     * @param
     */
    @GetMapping("/drugCode/{drugCode}")
    public R<BaseDrugOnline> getInfoByDrugCode(@PathVariable String drugCode) {
        return R.ok(iBaseDrugOnlineService.getInfoByDrugCode(drugCode));
    }


}
